<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<%@include file="/view/common/common.jsp"%>


	<script type="text/javascript">
		function searchData() {
			$('#tab').datagrid('load',serializeForm($('#mySearchForm')));
		}
		
		function del(){
			var rows = $('#tab').datagrid('getSelections');
			if (rows.length != 1) {
				$.messager.alert('消息', '请选择一条数据!', 'info');
				return false;
			}
			$.messager.confirm('确认','您确认要删除?',function(r){    
			    if (r){    
			    	var url ='${ctx}/account/delEmployee.do';	
					$.post(url,{"id":rows[0].id},function(result){
						var result = eval('(' + result + ')');
						if (result.isSuc) {
							$.messager.alert('消息', result.msg, 'info');
							$('#tab').datagrid('reload');
						} else {
							$.messager.alert('错误', result.msg, 'error');
						}
					}) 
			    }    
			});
		}

		//修改员工
		function edit() {
			var rows = $('#tab').datagrid('getSelections');
			if (rows.length != 1) {
				$.messager.alert('消息', '请选择一条数据!', 'info');
				return false;
			}
			$("#system_user_addDialog").dialog({
				modal : true,
				iconCls : 'icon-edit',
				title : '修改员工',
				width : 300,
				cache : false,
				shadow:false,
				closed : false
			});
			$('#my_form_update').form('load',{
				id:rows[0].id,
				realName:rows[0].real_name,
				account:rows[0].account,
				tel:rows[0].tel,
				typeStr:rows[0].type,
			});

		}
		
		function update() {
			var	url ='${ctx}/account/updateEmployee.do';
			$("#my_form_update").form('submit', {
				url : url,
				onSubmit : function() {
					if ($(this).form('validate') == false) {
						return false;
					}
					return true;
				},
				success : function(result) {
					var result = eval('(' + result + ')');
					if (result.isSuc) {
						$.messager.alert('消息', result.msg, 'info');
						$("#system_user_addDialog").dialog("close");
						$('#tab').datagrid('reload');
					} else {
						$.messager.alert('错误', result.msg, 'error');
					}
				}
			});
		}
		
		//增加员工
		function add() {
			$("#system_add_addDialog").form('clear')
			$("#type").combobox("setValue", 1);
			$("#system_add_addDialog").dialog({
				modal : true,
				iconCls : 'icon-add',
				title : '增加员工',
				width : 300,
				cache : false,
				shadow:false,
				closed : false
			});
			
		}
		
		function saveEmployee() {
				var	url ='${ctx}/account/insertEmployee.do';
				$("#my_form_add").form('submit', {
					url : url,
					onSubmit : function() {
						if ($(this).form('validate') == false) {
							return false;
						}
						return true;
					},
					success : function(result) {
						var result = eval('(' + result + ')');
						if (result.isSuc) {
							$.messager.alert('消息', result.msg, 'info');
							$("#system_add_addDialog").dialog("close");
							$('#tab').datagrid('reload');
						} else {
							$.messager.alert('错误', result.msg, 'error');
						}
					}
				});
			}
		
		
		
		
		
		function confinedTrade(val, row) {
			if (val == '0') {
				return '超级';
			} else if(val == '1'){
				return '普通';
			}
		}
		
	</script>

</head>
<body>

<div class="easyui-panel" fit="true">
	<div id="jqueryToolbar" style="padding:auto;height:auto">
		<div style="margin-top:5px; padding-bottom:8px; border-bottom:1px solid #ccc;">
			<form id="mySearchForm" action="" method="Post">
				手机:	<input type="text" id="phone" name="phone" class="easyui-textbox"  style="width: 100px; height: 25px;"/>
				<a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="searchData()">查询</a>
			</form>
		</div>
	</div>
	
	<div id="system_user_list_tb" style="height: auto; padding-left: auto;">
		<c:if test="${SESSION_INFO_OBJECT.type==0}">
			<a href="#" class="easyui-linkbutton" onclick="add()" data-options="iconCls:'icon-add',plain:true">增加员工</a>
			<a href="#" class="easyui-linkbutton" onclick="edit()" data-options="iconCls:'icon-edit',plain:true">修改员工</a>
			<!-- <a href="#" class="easyui-linkbutton" onclick="del()" data-options="iconCls:'icon-edit',plain:true">删除员工</a> -->
		</c:if>
	</div>
	<table id="tab" class="easyui-datagrid" fit="true" style="height:auto;width:auto;" url="${ctx}/account/getEmployee.do"
		   rownumbers="true" pagination="true" pagePosition="top" singleSelect="true"  toolbar="#system_user_list_tb">
		<thead>
		<tr>
			<th field="id"  width="80" align="center" style="display: none;">员工ID</th>
			<th field="real_name"  width="80" align="center">昵称</th>
			<th field="tel" width="130" align="center">手机</th>
			<th field="account" width="80" align="center">登录账号</th>
			<th field="type" width="80" align="center" data-options="formatter:confinedTrade" >员工类型</th>
			<th field="create_time"  width="135" align="center">创建时间</th>
			<th field="update_time"  width="135" align="center">修改时间</th>
		</tr>
		</thead>
	</table>


	<!-- 修改 ------------start -->
	<div id="system_user_addDialog"  class="easyui-dialog"  data-options="closed:true"  buttons="#addButs1">
		<form id="my_form_update" method="post">

			<input type="hidden" id="id" name="id"    >

			<table style="margin: 10px 20px;">
				<tr>
					<td style="text-align: right;">员工昵称:</td>
					<td><input type="text" id="real_name" name="realName"       style="width: 150px; height: 25px;" class="easyui-textbox"  data-options="required:true,missingMessage:'为必填项'" ></td>
				</tr>
				<tr>
					<td style="text-align: right;">员工手机:</td>
					<td><input type="text" id="tel" name="tel"       style="width: 150px; height: 25px;" class="easyui-numberbox"  data-options="required:true,missingMessage:'为必填项'" ></td>
				</tr>
				<tr>
					<td style="text-align: right;">登录账号:</td>
					<td><input type="text" id="account" name="account"   disabled="disabled"    style="width: 150px; height: 25px;" class="easyui-textbox"  data-options="required:true,missingMessage:'为必填项'" ></td>
				</tr>
				<tr>
					<td style="text-align: right;">登录密码:</td>
					<td><input type="text" id="pwd" name="pwd"       style="width: 150px; height: 25px;" class="easyui-textbox"  data-options="required:false,missingMessage:'可填项'" ></td>
				</tr>
				<tr>
					<td style="text-align: right;">交易密码:</td>
					<td><input type="text" id="trade_pwd" name="tradePwd"       style="width: 150px; height: 25px;" class="easyui-textbox"  data-options="required:false,missingMessage:'为必填项'" ></td>
				</tr>
				<tr>
					<td style="text-align: right;">员工类型:</td>
					<td>
					  <select name="typeStr" id="typeStr" class="easyui-combobox" style="width:150px;height: 25px;" data-options="panelHeight:'auto'">
							<option value="0">超级</option>
							<option value="1">普通</option>
						</select>
					</td>
				</tr>
			</table>
		</form>
		<div id="addButs1"  >
			<a href="#" class="easyui-linkbutton"   onclick="update()"   style="width:80px;height:30px;" iconCls="icon-ok" >提交</a>
		</div>
	</div>
	
	<!-- 添加 -------------->
	<div id="system_add_addDialog"  class="easyui-dialog"  data-options="closed:true"  buttons="#addButs2">
		<form id="my_form_add" method="post">

			<table style="margin: 10px 20px;">
				<tr>
					<td style="text-align: right;">员工昵称:</td>
					<td><input type="text" id="real_name1" name="realName"       style="width: 150px; height: 25px;" class="easyui-textbox"  data-options="required:true,missingMessage:'为必填项'" ></td>
				</tr>
				<tr>
					<td style="text-align: right;">员工手机:</td>
					<td><input type="text" id="tel1" name="tel"       style="width: 150px; height: 25px;" class="easyui-numberbox"  data-options="required:true,missingMessage:'为必填项'" ></td>
				</tr>
				<tr>
					<td style="text-align: right;">登录账号:</td>
					<td><input type="text" id="account1" name="account"       style="width: 150px; height: 25px;" class="easyui-textbox"  data-options="required:true,missingMessage:'为必填项'" ></td>
				</tr>
				<tr>
					<td style="text-align: right;">登录密码:</td>
					<td><input type="text" id="pwd1" name="pwd"       style="width: 150px; height: 25px;" class="easyui-textbox"  data-options="required:true,missingMessage:'为必填项'" ></td>
				</tr>
				<tr>
					<td style="text-align: right;">交易密码:</td>
					<td><input type="text" id="trade_pwd1" name="tradePwd"       style="width: 150px; height: 25px;" class="easyui-textbox"  data-options="required:true,missingMessage:'为必填项'" ></td>
				</tr>
				<tr>
					<td style="text-align: right;">员工类型:</td>
					<td>
					  <select name="type" id="type" class="easyui-combobox" style="width:150px;height: 25px;" data-options="panelHeight:'auto',required:true,missingMessage:'为必填项'">
							<option value="0">超级</option>
							<option value="1">普通</option>
						</select>
					</td>
				</tr>
			</table>
		</form>
		<div id="addButs2"  >
			<a href="#" class="easyui-linkbutton"   onclick="saveEmployee()"   style="width:80px;height:30px;" iconCls="icon-ok" >提交</a>
		</div>
	</div>

</div>
</body>
</html>
